/*
 * @Author: Sam
 * @Date: 2020-09-16 10:31:05
 * @LastEditTime: 2021-03-01 17:32:20
 * @LastEditors: Sam
 * @Description:
 * @FilePath: \tofba-client\src\utils\city-pcas.js
 * @可以输入预定的版权声明、个性签名、空行等
 */
const pcas = require('./pcas.json')

export function getPcas () {
  const cityData = []
  for (const i in pcas) {
    const obj = {}
    obj.value = i
    obj.label = i
    const children = []
    // 市
    for (const j in pcas[i]) {
      const obj2 = {}
      obj2.value = j === '市辖区' ? i : j
      obj2.label = j === '市辖区' ? i : j

      const children2 = []
      // 区
      for (const k in pcas[i][j]) {
        const obj3 = {}
        obj3.value = k
        obj3.label = k

        obj3.children = []
        // 街道
        for (const l of pcas[i][j][k]) {
          const obj4 = {}
          obj4.value = l
          obj4.label = l
          obj3.children.push(obj4)
        }

        children2.push(obj3)
      }

      obj2.children = children2
      children.push(obj2)
    }
    obj.children = children
    cityData.push(obj)
  }

  return cityData
}

export function getPcs () {
  const cityData = []
  for (const i in pcas) {
    const obj = {}
    obj.value = i
    obj.label = i
    const children = []
    // 市
    for (const j in pcas[i]) {
      const obj2 = {}
      obj2.value = j === '市辖区' ? i : j
      obj2.label = j === '市辖区' ? i : j

      const children2 = []
      // 区
      for (const k in pcas[i][j]) {
        const obj3 = {}
        obj3.value = k
        obj3.label = k
        children2.push(obj3)
      }

      obj2.children = children2
      children.push(obj2)
    }
    obj.children = children
    cityData.push(obj)
  }

  return cityData
}

export function getPc () {
  const cityData = []
  for (const i in pcas) {
    const obj = {}
    obj.value = i
    obj.label = i
    const children = []
    // 市
    for (const j in pcas[i]) {
      const obj2 = {}
      obj2.value = j === '市辖区' ? i : j
      obj2.label = j === '市辖区' ? i : j
      children.push(obj2)
    }
    obj.children = children
    cityData.push(obj)
  }

  return cityData
}
